package com.zcf.pojo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;

import com.zcf.gameController.gameUtils.gameLogic;
import lombok.Data;

/**
	 *@Author:ZhaoQi
	 *@methodName:房间属性
	 *@Params:
	 *@Description:
	 *@Return:
	 *@Date:2019/2/12
	 */
@Data
public class RoomsParam implements Cloneable{
	/**
	 * 游戏是否开始   0等人阶段  1定庄阶段  2下注阶段发牌  3开牌倒计时
	 */
	private Integer isStart;
	/**
	 * 房间号
	 */
	private String roomName;
	/**
	 * 对局ID
	 */
	private Integer gameId;
	/**
	 * 是否已有人当庄，有的话存储庄家ID
	 */
	private Long isUp=0L;
	/**
	 * 话事人数
	 */
	private Integer talkNum;
	/**
	 * 房间内的锁
	 */
	private Lock lock;
	/**
	 * 房间的牌(初始化方式不一样)
	 */
	private List<Integer> roomCards;
	/**
	 * 房间的玩家
	 */
	private Map<String, UserBean> users;
	/**
	 * 开房的参数类型
	 */
	private Map<String,Integer> roomType;
	/**
	 * 0初级1中级2高级
	 */
	private Integer roomGrade;
	/**
	 * 房间最低入场
	 */
	private Integer roomPoints;
	/**
	 *做庄金币限制
	 */
	private Integer bankerMoney;
	/**
	 * 房间内的所有位置
	 */
	private List<Integer> postions;
	/**
	 * 在做所有位置的牌
	 */
	private Map<Integer,List<Integer>> cards;
	/**
	 * 在做所有位置的牌输赢
	 */
	private Map<Integer,Integer> bunko;
	/**
	 * 在做所有位置的下注标识
	 */
	private Map<Integer,Integer> betMap;
	/**
	 * 在做所有位置的下注集合
	 */
	private Map<Integer,Integer> betMoeny;
	/**
	 * 倒计时时间
	 */
	private Integer timer=-1;

	private Integer sitting=0;
	/**
	 * 特殊牌型
	 */
	private String[] specialcard;
	/**
	 * 高级选项
	 */
	private String[] hoptions;
	/**
	 * 支付金额
	 */
	private Integer paymoney;
	/**
	 *房主
	 */
	private Long founder;
	/**
	 * 抽水
	 */
	private Double pumping;
	/**
	 * 俱乐部名称
	 */
	private String clubName;
	/**
	 * 同意人数
	 */
	private Integer agreenum = 0;
	/**
	 * 准备人数
	 */
	private Integer preparenum;
	/**
	 * 操作人id
	 */
	private Integer operation_userid;
	/**
	 * 房间总分
	 */
	private Integer downpool;
	/**
	 * 轮数
	 */
	private Integer number_rounds;
	/**
	 * 赢家
	 */
	private Integer winner;
	/**
	 * 游戏类型
	 * 0推筒子
	 * 1三公
	 */
	private Integer gametype;

	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	public RoomsParam getCoutom(){
		RoomsParam room = new RoomsParam();
		room.setIsStart(isStart);
		room.setRoomName(roomName);
		room.setGameId(gameId);
		room.setIsUp(isUp);
		room.setTimer(timer);
		return room;
	}
	public Map<String, Object> returnMap(Map<String, Object> data, String string){
		String[] strs = string.split("-");
		for (String str : strs) {
			if(str.equals("roomName")){
				data.put("roomName", this.roomType.get("roomName"));
			}
			if(str.equals("points")){
				data.put("points", this.roomType.get("points"));
			}
			if(str.equals("num")){
				data.put("num", this.roomType.get("num"));
			}
			if(str.equals("gameType")){
				data.put("gameType", this.roomType.get("gameType"));
			}
			if(str.equals("gameNum")){
				data.put("gameNum", this.gameId);
			}
			if(str.equals("downpool")){
				data.put("downpool", this.downpool);
			}
			if(str.equals("stuffynum")){
				data.put("stuffynum", this.roomType.get("stuffynum"));
			}
			if(str.equals("subsection")){
				data.put("subsection", this.roomType.get("subsection"));
			}
			if(str.equals("number_rounds")){
				data.put("number_rounds", this.number_rounds);
			}
			if(str.equals("points")){
				data.put("points", this.roomType.get("points"));
			}
		}
		return data;
	}
	
	/**
	 * 返回某一个用户
	 * @param userid
	 * @return
	 */
	public UserBean getUserBean(Long userid){
		for(UserBean userBean:users.values()){
			if(userBean.getId().equals(userid)){
				return userBean;
			}
		}
		return null;
	}
	
	//初始化房间
		public void Initialization(){
			//初始化扑克牌1副牌
			this.roomCards = gameLogic.getCards(this.gametype);
			//当前轮数
			this.number_rounds=1;
			//初始化用户
			for(com.zcf.pojo.UserBean user:this.users.values()){
				if (user.getType()==1&&user.getIsReady()==1){
					user.getBetList().clear();
					user.setOpentionType(0);
					user.setWinNumber(0);
					user.setSumWinnumber(0);
					user.setOpenCards(0);
					user.setUserCards(new ArrayList<Integer>());
				}
			}
			//清空锅底
			this.downpool=0;
			//初始化底注
//			this.bets=Integer.parseInt(room_money_parameter[1]);
			//启用一个房间线程用来开始游戏
//			StartGame_F startGame=new StartGame_F(this);
//			//startGame.setName(room_number);
//			startGame.start();
		}
		/**
		* @description :结束，初始化房间
		* @date : 2019/11/18 16:13
		* @author : jj
		*/
	public void	clear(){
		for(com.zcf.pojo.UserBean user:this.users.values()){
				user.getBetList().clear();
				user.setIsReady(0);
				user.setOpentionType(0);
				user.setWinNumber(0);
				user.setSumWinnumber(0);
				user.setOpenCards(0);
				user.setIsThread(30);
				user.setTotal(0);
				user.setUserCards(new ArrayList<Integer>());
				if(this.getIsUp().equals(user.getId())&&user.getIsOwner()==1) {
					user.setIsOwner(4);
				}else {
					user.setIsOwner(-1);
				}

		}
		if (this.getGametype()>0){
			for (int i=0;i<this.getPostions().size();i++){
				this.getBetMoeny().put(i,0);
			}
		}else {
			for (int i=0;i<this.getPostions().size()-1;i++){
				this.getBetMoeny().put(i,0);
			}
		}
		this.bunko.clear();
		this.cards.clear();
		this.betMap.clear();
		this.sitting=0;
		//this.isUp=0L;
	}
}
